package com.cll.mapper;


import com.cll.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.Map;

@Mapper
public interface UserMapper {

    /**
     * 根据openId获取用户登录数据
     * @return
     */
    @Select("select * from user where openid = #{openid}")
    User getByOpenId(String openId);


    /**
     * 添加用户  获取主键生成主键 @Options(useGeneratedKeys = true,keyProperty = "id")
     * @param user
     */
    @Insert("insert into user\n" +
            "values (null, #{openid}, #{name}, #{phone}, #{sex}, #{idNumber}, #{avatar}, #{createTime})")
    @Options(useGeneratedKeys = true,keyProperty = "id")
    void save(User user);

    @Select("select * from user where id = #{userId}")
    User getById(Long userId);

    /**
     * 用户统计
     * @param map
     * @return
     */
    Integer countByMap(Map<String, Object> map);
}
